<?php

namespace Admin\Api\Controllers;

//use Phalcon\Mvc\Controller;
use Phalcon\Mvc\Dispatcher;
use Helpers\Controller;

class ControllerBase extends Controller
{
    protected static $module = 'api';

    public function beforeExecuteRoute(Dispatcher $dispatcher)
    {
        header('Access-Control-Allow-Origin:*');
    }

//    public function afterExecuteRoute(Dispatcher $dispatcher)
//    {
//
//    }


    /**
     * @param int $code
     * @param string $msg
     * @param string $description
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by ck 20170814
     *
     * @SWG\Response(response="Error", description="错误", @SWG\Schema(ref="#/definitions/Error")),
     */
//    public function sendErrorResponse($code = 200, $msg = '未知错误', $description = '')
//    {
//        return $this->response->setStatusCode($code)
//            ->setJsonContent(['code' => $code, 'msg' => $msg,  'description' => $description], JSON_UNESCAPED_UNICODE);
//    }

    /**
     * function explain
     *
     * @param string $msg
     * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface
     *
     * create by ck 20170814
     *
     * @SWG\Response(response="Success", description="成功", @SWG\Schema(ref="#/definitions/Success")),
     */
//    public function sendSuccessResponse($msg = '成功')
//    {
//        return $this->response->setJsonContent(['code' => 200, 'msg' => $msg], JSON_UNESCAPED_UNICODE);
//    }
//
//    public function sendJsonResponse($array = [])
//    {
//        return $this->response->setJsonContent($array, JSON_UNESCAPED_UNICODE);
//    }

}

/**
 * @SWG\Definition(
 *      definition="Success",
 *      required={"code", "msg"},
 *      @SWG\Property(property="code", description="状态码", type="integer"),
 *      @SWG\Property(property="msg", description="成功信息", type="string")
 * )
 */

/**
 * @SWG\Definition(
 *      definition="Error",
 *      required={"code", "error"},
 *      @SWG\Property(property="code", description="错误码", type="integer"),
 *      @SWG\Property(property="error", description="错误信息", type="string"),
 *      @SWG\Property(property="msg", description="错误描述", type="string")
 * )
 */